package com.ruoyi.answer.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.answer.mapper.QtAnswerMapper;
import com.ruoyi.answer.domain.QtAnswer;
import com.ruoyi.answer.service.IQtAnswerService;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 答疑Service业务层处理
 * 
 * @author zqq
 * @date 2021-11-19
 */
@Service
public class QtAnswerServiceImpl implements IQtAnswerService 
{
    @Resource
    private QtAnswerMapper qtAnswerMapper;

    /**
     * 查询答疑
     * 
     * @param answerId 答疑主键
     * @return 答疑
     */
    @Override
    public QtAnswer selectQtAnswerByAnswerId(String answerId)
    {
        return qtAnswerMapper.selectQtAnswerByAnswerId(answerId);
    }

    /**
     * 查询答疑列表
     * 
     * @param qtAnswer 答疑
     * @return 答疑
     */
    @Override
    public List<QtAnswer> selectQtAnswerList(QtAnswer qtAnswer)
    {
        return qtAnswerMapper.selectQtAnswerList(qtAnswer);
    }

    /**
     * 新增答疑
     * 
     * @param qtAnswer 答疑
     * @return 结果
     */
    @Override
    public int insertQtAnswer(QtAnswer qtAnswer)
    {

        qtAnswer.setAnswerTime(DateUtils.getNowDate());
        qtAnswer.setAnswerState(1);
        qtAnswer.setAnswerId(IdUtils.randomUUID());
        return qtAnswerMapper.insertQtAnswer(qtAnswer);
    }

    /**
     * 修改答疑
     * 
     * @param qtAnswer 答疑
     * @return 结果
     */
    @Override
    @Transactional
    public int updateQtAnswer(QtAnswer qtAnswer)
    {
        QtAnswer qt=new QtAnswer();
        String id=IdUtils.randomUUID();
        qt.setAnswerId(id);
        qt.setAnswerTime(DateUtils.getNowDate());
        qt.setAnswerContent(qtAnswer.getReplyContent());
        qt.setUserId(qtAnswer.getAnswerInt().toString());
        qtAnswerMapper.insertQtAnswer(qt);//插入一条回复


        QtAnswer qt1=new QtAnswer();
        qt1.setReplyId(id);
        qt1.setAnswerState(2);
        qt1.setAnswerId(qtAnswer.getAnswerId());
        //修改答疑的回复id为已回复
        return qtAnswerMapper.updateQtAnswer(qt1);
    }

    /**
     * 批量删除答疑
     * 
     * @param answerIds 需要删除的答疑主键
     * @return 结果
     */
    @Override
    public int deleteQtAnswerByAnswerIds(String[] answerIds)
    {
        return qtAnswerMapper.deleteQtAnswerByAnswerIds(answerIds);
    }

    /**
     * 删除答疑信息
     * 
     * @param answerId 答疑主键
     * @return 结果
     */
    @Override
    public int deleteQtAnswerByAnswerId(String answerId)
    {
        return qtAnswerMapper.deleteQtAnswerByAnswerId(answerId);
    }
}
